﻿package mortal.game.scene3D.fight.dramaEffect.rule
{
    import baseEngine.core.*;
    import com.gengine.core.frame.*;
    import com.gengine.utils.*;
    import com.gengine.utils.pools.*;
    import mortal.game.scene3D.fight.dramaEffect.data.*;
    import mortal.game.scene3D.player.entity.*;

    public class DramaUniformRule extends Object
    {
        protected var _effectPlayer:Pivot3D;
        protected var _dramaMoveData:DramaMoveData;
        protected var _endCallBack:Function;
        protected var _timer:FrameTimer;
        protected var _startX:int;
        protected var _startY:int;
        protected var _endX:int;
        protected var _endY:int;
        protected var _currentX:int;
        protected var _currentY:int;
        protected var _runTime:int = 0;

        public function DramaUniformRule()
        {
            return;
        }// end function

        public function play(param1:Pivot3D, param2:DramaMoveData, param3:Function = null) : void
        {
            this._endCallBack = param3;
            this._effectPlayer = param1;
            this._dramaMoveData = param2;
            this._startX = this._dramaMoveData.startX;
            this._startY = this._dramaMoveData.startY;
            this._endX = this._dramaMoveData.endX;
            this._endY = this._dramaMoveData.endY;
            this._currentX = this._startX;
            this._currentY = this._startY;
            this._effectPlayer.scaleX = this._dramaMoveData.startScale;
            this._effectPlayer.scaleY = this._dramaMoveData.startScale;
            this._effectPlayer.scaleZ = this._dramaMoveData.startScale;
            this._timer = new FrameTimer(1, int.MAX_VALUE, true);
            this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrame);
            this._timer.start();
            return;
        }// end function

        private function onEnterFrame(param1:FrameTimer) : void
        {
            var _loc_4:Number = NaN;
            var _loc_5:Number = NaN;
            this._runTime = this._runTime + param1.interval;
            if (param1.isRepair)
            {
                return;
            }
            var _loc_2:* = MathUitl.getRadiansByXY(this._dramaMoveData.startX, this._dramaMoveData.startY, this._dramaMoveData.endX, this._dramaMoveData.endY);
            var _loc_3:* = MathUitl.getDistance(this._startX, this._endX, this._startY, this._endY);
            if (this._dramaMoveData.moveTime > 0)
            {
                _loc_4 = this._runTime / this._dramaMoveData.moveTime;
            }
            else
            {
                _loc_4 = 0;
            }
            if (_loc_4 < 1)
            {
                this._currentX = this._startX + Math.cos(_loc_2) * _loc_4 * _loc_3;
                this._currentY = this._startY + Math.sin(_loc_2) * _loc_4 * _loc_3;
                (this._effectPlayer as IGame2D).x2d = this._currentX;
                (this._effectPlayer as IGame2D).y2d = this._currentY;
                _loc_5 = this._dramaMoveData.startScale + _loc_4 * (this._dramaMoveData.endScale - this._dramaMoveData.startScale);
                this._effectPlayer.scaleX = _loc_5;
                this._effectPlayer.scaleY = _loc_5;
                this._effectPlayer.scaleZ = _loc_5;
            }
            else
            {
                this.playEnd();
            }
            return;
        }// end function

        protected function playEnd() : void
        {
            if (this._endCallBack != null)
            {
                this._endCallBack.call();
            }
            this.dispose();
            return;
        }// end function

        public function dispose() : void
        {
            this._timer.stop();
            this._timer.dispose();
            this._timer = null;
            this._effectPlayer = null;
            this._endCallBack = null;
            this._dramaMoveData = null;
            this._runTime = 0;
            ObjectPool.disposeObject(this);
            return;
        }// end function

    }
}
